package com.feixiu.mapreduce.partionertest;


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * 不仅仅获取设置流量计算   最后还要根据省份，把不同省份的号码划分开文件
 *   这个就需要自定义一个partionner  类，重新实现就可以了
 */
public class FlowDriver {


    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        //1.获取job
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);


        //2.关联jar包
        job.setJarByClass(FlowDriver.class);

        //3、关联mapper和reducer
        job.setMapperClass(FlowMapper.class);
        job.setReducerClass(FlowReducer.class);
        //4.设置mapper  输出的key 和value类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(FlowBean.class);

        //5.设置最终输出的key和value 类型
        job.setOutputKeyClass(LongWritable.class);
        job.setOutputValueClass(Text.class);

        job.setPartitionerClass(ProvincePatitionner.class);//设置partition  类
        job.setNumReduceTasks(5);//设置分区数：
        //如果分区数和你在patitioner中设置的不一样的，少的话就会报io错误，多的话，就会产生空的数据文件
        //6. 设置数据的输入路径和输出路径
        FileInputFormat.setInputPaths(job, new Path("D:\\Desktop\\temp\\input\\inputflow\\phone_data.txt"));
        FileOutputFormat.setOutputPath(job, new Path("D:\\Users\\hadoop\\outputPartition"));
        //7.提交job  true  打印的日志信息更全
        boolean result = job.waitForCompletion(true);
        System.exit(result ? 0 : 1);
    }
}
